package textviewer.main;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuItem;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

public class GUIInternetList extends Activity{
	private Config myconfig;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ScrollView scllview = new ScrollView(this);
        ScrollView.LayoutParams scllview_param = new ScrollView.LayoutParams(
        		ViewGroup.LayoutParams.FILL_PARENT,
        		ViewGroup.LayoutParams.FILL_PARENT);
        scllview.setBackgroundColor(Color.WHITE);
        myconfig = new Config(this);
        scllview.setBackgroundDrawable(myconfig.return_bg());
        LinearLayout Llay = new LinearLayout(this);
        LinearLayout.LayoutParams Llay_param = new LinearLayout.LayoutParams(
        		ViewGroup.LayoutParams.FILL_PARENT,
        		ViewGroup.LayoutParams.FILL_PARENT);
        Llay.setOrientation(LinearLayout.VERTICAL);
        ArrayList<String> server_names = Utility.return_server_list_name();
        ArrayList<String> server_urls = Utility.return_server_list_url();
        LinearLayout list1 = new LinearLayout(this);
        LinearLayout.LayoutParams list1_param = new LinearLayout.LayoutParams(
        		ViewGroup.LayoutParams.WRAP_CONTENT,
        		ViewGroup.LayoutParams.WRAP_CONTENT);
        TextView list1_txtview = new TextView(this);
        list1_txtview.setText("1."+server_names.get(0)+"\n"+server_urls.get(0));
        list1_txtview.setTextColor(Color.BLACK);
        list1_txtview.setTextSize(TypedValue.COMPLEX_UNIT_SP,(float)21);
        list1.addView(list1_txtview);
        PanelOnTouchListener tmp_cl = new PanelOnTouchListener(list1_txtview);
        list1.setClickable(true);
        list1.setOnTouchListener(tmp_cl);
        InternetListClickListener ilcl = new InternetListClickListener(this,(int)0);
        list1.setOnClickListener(ilcl);
        Llay.addView(list1,list1_param);

        
        LinearLayout list2 = new LinearLayout(this);
        LinearLayout.LayoutParams list2_param = new LinearLayout.LayoutParams(
        		ViewGroup.LayoutParams.WRAP_CONTENT,
        		ViewGroup.LayoutParams.WRAP_CONTENT);
        TextView list2_txtview = new TextView(this);
        list2_txtview.setText("2."+server_names.get(1)+"\n"+server_urls.get(1));
        list2_txtview.setTextColor(Color.BLACK);
        list2_txtview.setTextSize(TypedValue.COMPLEX_UNIT_SP,(float)21);
        list2.addView(list2_txtview);
        PanelOnTouchListener tmp_cl2 = new PanelOnTouchListener(list2_txtview);
        list2.setClickable(true);
        list2.setOnTouchListener(tmp_cl2);
        InternetListClickListener ilcl2 = new InternetListClickListener(this,(int)1);
        list2.setOnClickListener(ilcl2);
        Llay.addView(list2,list2_param);
        
        LinearLayout list3 = new LinearLayout(this);
        LinearLayout.LayoutParams list3_param = new LinearLayout.LayoutParams(
        		ViewGroup.LayoutParams.WRAP_CONTENT,
        		ViewGroup.LayoutParams.WRAP_CONTENT);
        TextView list3_txtview = new TextView(this);
        list3_txtview.setText("3."+server_names.get(2)+"\n"+server_urls.get(2));
        list3_txtview.setTextColor(Color.BLACK);
        list3_txtview.setTextSize(TypedValue.COMPLEX_UNIT_SP,(float)21);
        list3.addView(list3_txtview);
        PanelOnTouchListener tmp_cl3 = new PanelOnTouchListener(list3_txtview);
        list3.setClickable(true);
        list3.setOnTouchListener(tmp_cl3);
        InternetListClickListener ilcl3 = new InternetListClickListener(this,(int)2);
        list3.setOnClickListener(ilcl3);
        Llay.addView(list3,list3_param);
        
        
        scllview.addView(Llay, Llay_param);
        
        this.setTitle("Gather books from Internet");
        this.setContentView(scllview, scllview_param);
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    	menu.add(0, 0, 0, "Return to BookShelf").setIcon(android.R.drawable.ic_menu_revert);
    	return super.onCreateOptionsMenu(menu); 
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    	if(item.getItemId()==0)
    	{
    		Intent int_ent = new Intent(this, GUIBookShelfBkSelect.class);
    		this.startActivity(int_ent);
    		finish();
    	}
    	return super.onOptionsItemSelected(item); 
    }
}
